2021-08-31
…the study and practice of making maps. Combining science, aesthetics, and technique, cartography builds on the premise that reality can be modeled in ways that communicate spatial information effectively.
So let’s flex some cartographic muscle and avoid cartostrophe
Here are a sample:
Columbia University Map
New York Times Election Map
3D Terrain Map
How New Yorkers See The World
Animal Migration with Climate Change
Elements of a basic map
tm_polygons Create a polygon layer (with borders)tm_symbols Create a layer of symbolstm_lines Create a layer of linestm_raster Create a raster layertm_text Create a layer of text labelstm_basemap Create a layer of basemap tilestm_tiles Create a layer of overlay tilestm_fill Create a polygon layer (without borders)tm_borders Create polygon borderstm_bubbles Create a layer of bubblestm_squares Create a layer of squarestm_dots Create a layer of dotstm_markers Create a layer of markerstm_iso Create a layer of iso/contour linestm_rgb Create a raster layer of an image# create borders tm_shape(nycbb) + tm_borders()
# create the fill tm_shape(nycbb) + tm_fill()
# combine them tm_shape(nycbb) + tm_fill() + tm_borders()
## tmap example
# or polygons
tm_shape(nycbb) +
tm_polygons()
map1 <- tm_shape(nycbb) + tm_fill(col = "red") map2 <- tm_shape(nycbb) + tm_fill(col = "red", alpha = .2) map3 <- tm_shape(nycbb) + tm_borders(col = "grey") map4 <- tm_shape(nycbb) + tm_borders(col = "blue", lwd = 0.5, lty = 2) tmap_arrange(map1, map2, map3, map4)
The common classification methods are:
Classification Methods
Classification Methods on Maps
tm_layout Adjust the layout (main function)tm_legend Adjust the legendtm_view Configure the interactive view modetm_style Apply a predefined styletm_format Apply a predefined formattm_grid Create grid linestm_scale_bar Create a scale bartm_compass Create a map compasstm_credits Create a text for creditstm_logo Create a logotm_xlab and tm_ylab Create axis labelstm_minimap Create a minimap (view mode only)Make three maps from your usCounties comparing the percent difference in areas.
Make sure to have a north arrow, scale bar, source, legend, and title.
You can add a projection on the fly by specifying the projection attribute in tm_shape too if you want to play with that.
subway <- read_sf( "../Shapes/SubwayLines") %>%
st_transform(2263) %>% mutate(rt_symbol = as.factor(rt_symbol))
subwayPalette <- c("1"='#EE352E', "4"='#00933C', "7"='#B933AD',
"A"='#0039A6',"B"='#FF6319', "G"= '#6CBE45',
"J"='#996633',"L"='#A7A9AC',"N"='#FCCC0A')
tm_shape(nycbb) + tm_borders(col = "grey") +
tm_shape(subway) +
tm_lines(col = 'rt_symbol', palette = subwayPalette) +
tm_facets(by = "rt_symbol", free.coords = FALSE, nrow = 3)
you might need image magick
we will use the tmap_animation function to create a gif.
The parameters that are important are: filename is the filename of the video (should be a .gif or .mpg file] delay is the time between images (in 1/100th of a second) so 4 seconds is 400. loop is a logical that determines whether the animation is looped, or an integer value that determines how many times the animation is looped.
subwayMaps <- tm_shape(nycbb, simplify = 0.8) +
tm_borders(col = "grey") +
tm_shape(subway) +
tm_lines(col = 'rt_symbol', palette = subwayPalette) +
tm_facets(along = "rt_symbol", free.coords = FALSE)
tmap_animation(subwayMaps, filename = "subway.gif",
delay = 150, loop = TRUE)
Leaflet is a great interactive mapping platform and couldn’t be simpler to add to your rmarkdown document/slides or shiny dashboards. It can deal with sf and sp objects so you don’t have to make any conversions with your spatial data!
we can set the view and add a provider tile
library(leaflet)
m <- leaflet() %>%
setView(lng = -73.9691305, lat = 40.7764627, zoom = 11) %>%
addProviderTiles(providers$CartoDB.Positron)
m
m %>% addPolygons(data = nycbb %>% st_transform(4326)) %>%
addPolylines(data = subway %>% st_transform(4326))
pal <- colorFactor(palette = c("#EE352E", "#00933C", "#B933AD",
"#0039A6", "#FF6319", "#6CBE45",
"#996633", "#A7A9AC", "#FCCC0A"),
levels = c("1", "4", "7", "A", "B",
"G", "J", "L", "N"))
m %>% addPolygons(data = nycbb %>% st_transform(4326),fillColor ="NA") %>%
addPolylines(data = subway %>% st_transform(4326),
color = ~pal(rt_symbol))
Add usCounties to a leaflet map and create a color palette for colorNumeric using one of your percent differences.